package com.cjkj.system.service.impl;

import com.cjkj.common.core.utils.bean.BeanUtils;
import com.cjkj.system.domain.TPatIndex;
import com.cjkj.system.domain.TPatVisit;
import com.cjkj.system.domain.vo.PatIndexVo;
import com.cjkj.system.mapper.TPatIndexMapper;
import com.cjkj.system.mapper.TPatVisitMapper;
import com.cjkj.system.service.ITPatIndexService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 患者基本信息Service业务层处理
 * 
 * @author cjkj
 * @date 2024-08-30
 */
@Service
public class TPatIndexServiceImpl implements ITPatIndexService 
{
    @Resource
    private TPatIndexMapper tPatIndexMapper;

    @Resource
    private TPatVisitMapper tVisitMapper;

    @Override
    public PatIndexVo getByIdentityNumber(String identityNumber, String hospitalId) {

        PatIndexVo vo = new PatIndexVo();

        // 查询患者信息
        TPatIndex tPatIndex = tPatIndexMapper.selectByIdNoAndHospitalId(identityNumber, hospitalId);
        if (tPatIndex != null) {
            BeanUtils.copyProperties(tPatIndex, vo);

            // 查询患者最新一条就诊记录
            TPatVisit tPatVisit = tVisitMapper.selectLastVisitRecordByPatientId(tPatIndex.getPatientId());
            if (tPatVisit != null) {
                // 如果不为空，取出诊断信息赋值到患者信息对象中
                vo.setDiagnosis(tPatVisit.getDiagnosis());
            }
        }

        return vo;
    }

}
